<!---
	Title:		Elders Program Manager
	Author:		Bruce Frick
	Purpose:	utilities functions for the software
--->
<cfcomponent extends="base">

    <!---simple session variable set--->
	<cffunction name="funcSetSessionElderID" access="remote" output="yes" returntype="any">
    	<cfargument name="ElderID" default="0" required="yes" />
    	<cfset SESSION.ElderID = ARGUMENTS.ElderID />
    	<cfreturn SESSION.ElderID />
    </cffunction>




    <!--- time validation --->
	<cffunction name="funcCompareTime" access="remote" output="yes" returntype="any">
    	<cfargument name="TimeIn" default="0" required="yes" />
        <cfargument name="TimeOut" default="0" required="yes" />

        <cftry>
			<cfset TimeIn = TimeFormat(TimeIn, "HH:mm") />
            <cfset TimeOut = TimeFormat(TimeOut, "HH:mm") />

            <cfif datecompare(TimeIn, TimeOut, "h") eq 0>
            <!---if TimeIn hour is EQUAL to TimeOut--->

                <cfif datecompare(TimeIn, TimeOut, "n") eq 0>
                <!---if TimeIn minutes is EQUAL to TimeOut--->
                    <cfset TimeObj = 0/>

                <cfelseif datecompare(TimeIn, TimeOut, "n") eq -1>
                <!---if TimeIn minutes is EARLIER than TimeOut--->

                    <cfset TimeObj = DateDiff("n", TimeIn, TimeOut) />
                    <cfset TimeObj = NumberFormat( Round((TimeObj / 15)) ) />
                    <cfreturn SerializeJSON(TimeObj) />
                <cfelse>
                    <cfset TimeObj = "ERROR" />
        			<cfreturn TimeObj />
                </cfif>

            <cfelseif datecompare(TimeIn, TimeOut, "h") eq -1>
            <!---if TimeIn hour is EARLIER than TimeOut--->

                <cfset TimeObj = DateDiff("n", TimeIn, TimeOut) />
                <cfset TimeObj = NumberFormat( Round((TimeObj / 15)) ) />
                <cfreturn SerializeJSON(TimeObj) />
            <cfelse>
                <cfset TimeObj = "ERROR" />
        		<cfreturn TimeObj />
            </cfif>

            <cfcatch type="any">
                <cfset TimeObj = "ERROR" />
                <cfreturn TimeObj />
            </cfcatch>
        </cftry>
    </cffunction>




    <!---simple session variable set--->
	<cffunction name="funcEvalDateSet" access="remote" output="yes" returntype="any">
    	<cfargument name="PlanDate" default="0" required="yes" />
        <cftry>
    		<Cfset EvalDate = dateAdd("yyyy", 1, PlanDate) />
        	<cfreturn dateFormat(EvalDate,'mm/dd/yyyy') />
        <cfcatch type="any">
        	<cfset EvalDate = "" />
            <cfreturn EvalDate />
        </cfcatch>
        </cftry>
    </cffunction>




    <!---simple session variable set--->
	<cffunction name="funcDateFormatSet" access="remote" output="yes" returntype="any">
    	<cfargument name="Date" default="0" required="yes" />
        <cftry>
	        <cfset Date = dateFormat(Date,'mm/dd/yyyy') />
        <cfcatch type="any">
        	<cfset Date = "" />
        </cfcatch>
        </cftry>
        <cfreturn dateFormat(Date,'mm/dd/yyyy') />
    </cffunction>




    <!--- test for blank values used in checkboxes--->
	<cffunction name="funcBooleanTest"  returntype="any">
    	<cfargument name="Obj" default="0" required="yes" />
        <cfif Obj eq ''>
        	<cfset Obj = 0 />
            <cfreturn Obj />
        <cfelse>
        	<cfreturn Obj />
        </cfif>
    </cffunction>




    <!---simple session variable get without ajaz--->
	<cffunction name="funcSetSessionElderIDNoAJAX"  returntype="any">
    	<cfargument name="ElderID" default="0" required="yes" />
    	<cfset SESSION.ElderID = ARGUMENTS.ElderID />
    	<cfreturn SESSION.ElderID />
    </cffunction>




    <!---simple session variable get--->
	<cffunction name="funcGetSessionElderID" access="remote" output="yes" returntype="any">
    	<cfreturn SESSION.ElderID />
    </cffunction>



    <!---simple session variable get--->
	<cffunction name="funcIsSupervisor" returntype="any">
    	<cfargument default="-1" name="Login" required="yes" />
    	<cfquery datasource="eldersprogram" name="qryGetSupervisors">
        	SELECT *
            FROM [Roles]
            WHERE [Login] = <cfqueryparam value="#ARGUMENTS.Login#" cfsqltype="cf_sql_varchar" />
            	AND [Role] = <cfqueryparam value="Supervisor" cfsqltype="cf_sql_varchar" />
        </cfquery>
        <cfreturn  qryGetSupervisors />
    </cffunction>




    <!---elder last name autosuggest--->
    <cffunction name="funcSearchLastNameSuggest" access="remote" returntype="any">

		<cfset provideArray = "" />
        <cfset elders = CreateObject("component", "queries").funcQryAllEldersNoContacts() />
		<cfloop from="1" to="#elders.RecordCount#" index="i" >
			<cfset provideArray = provideArray &
				#Replace(Replace(elders.LastName[i],"'","`","All"), '"', '`', 'All')# & " " &
				#Replace(Replace(elders.FirstName[i], "'", "`", "All"), '"', '`', 'All')# &  " - " &
				#elders.ElderListID[i]#  />
        	<cfif i neq elders.RecordCount>
        		<cfset provideArray = provideArray & "," />
        	</cfif>
		</cfloop>
		<cfreturn provideArray />
    </cffunction>




    <!---elder last name autosuggest--->
    <cffunction name="funcSearchLastNameSuggestDict" access="remote" returntype="any">

		<cfset provideArray = "" />
        <cfset elders = CreateObject("component", "queries").funcQryAllEldersNoContacts() />
		<cfloop from="1" to="#elders.RecordCount#" index="i" >
			<cfset provideArray = provideArray & "{'" &
				#Replace(Replace(elders.LastName[i],"'","`","All"), '"', '`', 'All')# & " " &
				#Replace(Replace(elders.FirstName[i], "'", "`", "All"), '"', '`', 'All')# &  "' : " &
				#elders.ElderListID[i]# & "}" />
        	<cfif i neq elders.RecordCount>
        		<cfset provideArray = provideArray & "," />
        	</cfif>
		</cfloop>
		<cfreturn provideArray />
    </cffunction>




    <!--- Providers From SCF Elders Staff DL --->
    <cffunction name="funcGetDLProviders" returntype="any">
    	<cfargument default="-1" name="ProviderID" />
        <cfargument default="" name="Login" />

		<cfset Providers = SUPER.SCF_Exchange_GetEmployeesInDL("CN=SCF Elders Program,OU=Dynamic Groups,OU=SCFUsers,DC=SouthcentralFoundation,DC=com")/>

        <cfif ARGUMENTS.ProviderID NEQ -1 >
        	<cfreturn SUPER.SCF_Employee_GetEmployee(ARGUMENTS.ProviderID) />
        </cfif>

        <cfif ARGUMENTS.Login NEQ "" >
        	<cfreturn SUPER.SCF_Employee_GetEmployee(ARGUMENTS.Login) />
        </cfif>

        <cfreturn Providers />
    </cffunction>
    
    
    
    
    <!--- Providers From SCF Elders Staff DL to display on play neatly--->
    <cffunction name="funcShowDLProvider" returntype="any">
        <cfargument default="-1" name="ProviderID" />

        <cfset Providers = SUPER.SCF_Exchange_GetEmployeesInDL("CN=SCF Elders Program,OU=Dynamic Groups,OU=SCFUsers,DC=SouthcentralFoundation,DC=com")/>

        <cfif ARGUMENTS.ProviderID NEQ -1 >
            <cfreturn SUPER.SCF_Employee_GetEmployee(ARGUMENTS.ProviderID) />
        </cfif>

        <cfreturn  Providers />
    </cffunction>





    <!--- Providers From SCF Elders Staff DL --->
    <cffunction name="funcFindProvider" returntype="any">
    	<cfargument default="-1" name="ProviderID" />
        
        <cfset retVal = {ProviderName = "", ProviderID = -1} />
        
        <cfif ARGUMENTS.ProviderID EQ "">
        	<cfset ARGUMENTS.ProviderID = -1 />
        </cfif>
        
        <!--- <cfset isInDL = 0 />
        <cfset Providers = SUPER.SCF_Exchange_GetEmployeesInDL("CN=SCF Elders Program,OU=Dynamic Groups,OU=SCFUsers,DC=SouthcentralFoundation,DC=com")/>
        <cfloop from="1" to="#ArrayLen(Providers)#" index="i" >
			<cfif Providers[i].RosettaID EQ ARGUMENTS.ProviderID>
                 <cfset isInDL = 1 />
			</cfif>        
        </cfloop> --->
        <cftry>
        <cfif SUPER.SCF_Employee_GetEmployee(ARGUMENTS.ProviderID).FirstName NEQ "[Not Found]" <!--- AND isInDL NEQ 1 --->>
            <!--- DL Search --->
            <cfset retVal.ProviderName = SUPER.SCF_Employee_GetEmployee(ARGUMENTS.ProviderID).FirstName & ' ' & SUPER.SCF_Employee_GetEmployee(ARGUMENTS.ProviderID).LastName>
            <cfset retVal.ProviderID = ARGUMENTS.ProviderID />
            <Cfreturn retVal />
        <cfelse>
            <cfset retVal = {ProviderName = "[Not Found]", ProviderID = -1} />
            <cfreturn retVal>
        </cfif>
        
        <cfcatch type="any" >
            <cfset retVal = {ProviderName = "[Not Found]", ProviderID = -1} />
            <cfreturn retVal>
        </cfcatch>
        </cftry>

    </cffunction>


</cfcomponent>
.